package com.atstudy.controller;

import com.atstudy.entites.Account;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2023/2/15 11:12
 * @copyright: 博为峰
 */
@Controller
@RequestMapping("/account")
public class AccountController {

    //    @RequestMapping(value = "/getAccountList", method = RequestMethod.GET)
    @GetMapping(value = "/getAccountList")
    public String getAccountList() {
        System.out.println("getAccountList");
        return "account_list";
    }

    @RequestMapping(value = "/getAccountByName")
    public String getAccountByName(String name, @RequestParam(value = "money") int balance) {
        System.out.println("name = " + name);
        System.out.println("balance = " + balance);
        return "account_list";
    }

    //    @RequestMapping(value = "/addAccount", method = RequestMethod.POST)
    @PostMapping(value = "/addAccount")
    public String addAccount(Account account) {
        System.out.println("account = " + account);
        return "account_list";
    }

    @RequestMapping(value = "/getAccountByIdName/{id}/{name}")
    public String getAccountByIdName(@PathVariable("id") int id, @PathVariable("name") String name) {
        System.out.println("id = " + id);
        System.out.println("name = " + name);
        return "account_list";
    }

    @RequestMapping(value = "/getAccountByCt")
    public String getAccountByCt(Date ct) {
        System.out.println("ct = " + ct);
        return "account_list";
    }

    @RequestMapping(value = "/addAccountJson")
    @ResponseBody
    public Account addAccountJson(@RequestBody Account account) {
        System.out.println("account = " + account);
        return account;
    }

    @RequestMapping(value = "/testAnno")
    public String testAnno(@RequestHeader("User-Agent") String userAgent,
                            @CookieValue("JSESSIONID") String cookie,
                            HttpServletRequest request,
                            HttpServletResponse response,
                            HttpSession session) {
        System.out.println("userAgent = " + userAgent);
        System.out.println("cookie = " + cookie);
        System.out.println("request = " + request);
        return "account_list";
    }
}
